<template>
  <div v-if="canShowPage" id="notice">
    <!--上部搜索条件组件-->
    <topSearch :form-inline="formInline"></topSearch>
    <!-- 操作按钮 -->
    <div class="table-conBtn">
      <el-button type="warning" icon="el-icon-plus" @click="addRoles('add')">
        新增
      </el-button>
      <el-button type="warning" plain @click="delRoles">
        批量删除
      </el-button>
    </div>
    <!--下部table-->
    <el-table
      v-loading="loading"
      :data="tableData"
      stripe
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column
        type="selection"
        width="55"
        align="center"
      ></el-table-column>
      <el-table-column type="index" width="160" label="序号">
        <template slot-scope="scope">
          {{ scope.$index | filterPage(searchParams.pageNum, searchParams.pageSize) }}
        </template>
      </el-table-column>
      <el-table-column
        label="公告标题"
        prop="dapengNum"
        min-width="260"
      ></el-table-column>
      <el-table-column label="公告类型" prop="workPermission" min-width="280">
        <template slot-scope="scope">
          <span v-if="scope.row.status === '0'" class="tag-span primary"
            >通知</span
          >
          <span v-else class="tag-span warning">通知</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" prop="sharePermission" min-width="80">
        <template slot-scope="scope">
          <span v-if="scope.row.status === '0'" class="tag-span primary"
            >正常</span
          >
          <span v-else class="tag-span warning">停用</span>
        </template>
      </el-table-column>
      <el-table-column
        label="创建者"
        prop="eitor"
        min-width="100"
      ></el-table-column>
      <el-table-column
        label="创建时间"
        prop="createrDate"
        min-width="160"
      ></el-table-column>
      <el-table-column fixed="right" label="操作" width="120">
        <template slot-scope="scope">
          <el-button type="text" @click="addRoles(scope.row.id)">
            编辑
          </el-button>
          <el-button type="text" @click="handleEdit(scope.row.id)">
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--分页-->
    <div class="page">
      <el-pagination
        v-if="total > 0"
        background
        :layout="
          total <= searchParams.pageSize
            ? 'total'
            : 'total, prev, pager, next, jumper'
        "
        :total="total"
        :page-size="searchParams.pageSize"
        :current-page="searchParams.pageNum"
        @current-change="changePage"
      ></el-pagination>
    </div>
    <dialogAddEdit
      v-if="dialogData.isShow"
      :dialog-data="dialogData"
    ></dialogAddEdit>
  </div>
</template>
<script>
import topSearch from '@component/system/notice/topSearch' // 上部搜索条件
import dialogAddEdit from '@component/system/notice/dialogAddEdit' // 上部搜索条件
export default {
  name: 'Notice',
  msg: '通知公告',
  components: {
    topSearch,
    dialogAddEdit
  },
  data() {
    return {
      loading: false,
      canShowPage: true, // 是否显示当前页面
      page: 1, // 当前页数
      row: 10, // 页面显示条数
      total: 50,
      searchParams: {
        pageNum: 1, // 当前页数
        pageSize: 10 // 页面显示条数
      },
      tableData: [
        {
          id: 1,
          dapengNum: '1',
          workPermission: '已开通',
          sharePermission: '已开通',
          eitor: '徐敏',
          createrDate: '2019-09-12'
        },
        {
          id: 2,
          dapengNum: 'q',
          workPermission: '已开通',
          sharePermission: '已开通',
          eitor: '徐敏',
          createrDate: '2019-09-12'
        }
      ], // table内容
      formInline: {
        configName: '',
        status: '' // 状态0正常,1停用
      },
      // 新增
      dialogData: {
        isShow: false, // 默认隐藏
        type: '', // 默认新增
        params: '' // 编辑时，传递的参数
      }
    }
  },
  mounted() {},
  methods: {
    /* 新增、编辑 */
    addRoles(type, params = '') {
      this.dialogData.isShow = true
      this.dialogData.type = type
      this.dialogData.postId = params
    },
    /* 批量删除 */
    delRoles() {
      if (this.multipleSelection.length <= 0) {
        this.$message.warning('请至少选择一条数据！')
        return
      }
      this.$confirm(
        `确认删除这${this.multipleSelection.length}个岗位?`,
        '删除提示',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      )
    },
    /* 换页 */
    changePage(page) {
      this.page = page
      this.LoadData()
    },
    // table选择
    handleSelectionChange(val) {
      this.multipleSelection = val
      this.deldisabled = false
      this.editdisabled = true
      if (this.multipleSelection.length === 1) {
        this.editdisabled = false
      }
      if (this.multipleSelection.length === 0) {
        this.deldisabled = true
        this.editdisabled = true
      }
    },
    /* 搜索 */
    toSearch() {},
    /* 重置 */
    reset() {}
  }
}
</script>
<style lang="less"></style>
